//
//  GroupTableView.h
//  etionUI
//
//  Created by wangjian on 8/9/13.
//
//

#import <UIKit/UIKit.h>
#import "GroupTableViewCell.h"

@interface CGroupBackgroundInfo : NSObject

@property (nonatomic, retain) UIImage *image;
@property (nonatomic, assign) UIEdgeInsets borderEdgeInsets;
@property (nonatomic, assign) CGFloat cornerRadius;

+ (CGroupBackgroundInfo *)infoWithImage:(UIImage *)image borderEdgeInsets:(UIEdgeInsets)borderEdgeInsets cornerRadius:(CGFloat)cornerRadius;

@end

@class CGroupTableView;
@protocol CGroupTableViewDelegate <NSObject>

@required
- (NSInteger)groupTableView:(CGroupTableView *)groupTableView numberOfRowsInGroup:(NSInteger)group;
- (CGroupTableViewCell *)groupTableView:(CGroupTableView *)groupTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

@optional
- (NSUInteger)numberOfGroupInGroupTableView:(CGroupTableView *)groupTableView;
- (CGFloat)groupTableView:(CGroupTableView *)groupTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)groupTableView:(CGroupTableView *)groupTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

//- (CGFloat)groupTableView:(CGroupTableView *)groupTableView heightForHeaderInGroup:(NSInteger)group;
//- (CGFloat)groupTableView:(CGroupTableView *)groupTableView heightForFooterInGroup:(NSInteger)group;
- (UIView *)groupTableView:(CGroupTableView *)groupTableView viewForHeaderInGroup:(NSInteger)group;
- (UIView *)groupTableView:(CGroupTableView *)groupTableView viewForFooterInGroup:(NSInteger)group;

//返回nil，表示无背景
- (CGroupBackgroundInfo *)groupTableView:(CGroupTableView *)groupTableView groupBackgroundInfoForGroupIndex:(NSInteger)groupIndex;

@end

@interface CGroupTableView : UIView

@property (nonatomic, assign) id<CGroupTableViewDelegate> delegate;
@property (nonatomic, retain) UIScrollView *scrollView;

@property (nonatomic, assign) UIColor *groupBackgroundColor;    //default is clear color
@property (nonatomic, assign) CGFloat separatorSize;
@property (nonatomic, retain) UIColor *separatorColor;

@property (nonatomic, assign) UIEdgeInsets borderEdgeInsets;    //default is (10, 10, 10, 10)
@property (nonatomic, assign) CGFloat groupSpacing;               //default is 10

- (void)reloadData;
- (CGroupTableViewCell *)cellAtIndexPath:(NSIndexPath *)indexPath;
- (CGroupTableViewCell *)cellWithTag:(NSString*)szTag;
- (NSIndexPath *)indexPathOfCell:(CGroupTableViewCell *)cell;
- (CGRect)frameOfGroup:(NSUInteger)groupId;
- (CGRect)frameOfCellAtIndexPath:(NSIndexPath *)indexPath;

- (CGFloat)cellContentWidth;
- (void)setGroupBackgroundImageWithImage:(UIImage *)image borderEdgeInsets:(UIEdgeInsets)borderEdgeInsets cornerRadius:(CGFloat)cornerRadius;
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

- (void)scrollToIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

- (void)resizeRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation complete:(void (^)(BOOL finished))complete;
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation complete:(void (^)(BOOL finished))complete;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation complete:(void (^)(BOOL finished))complete;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation complete:(void (^)(BOOL finished))complete;

@end
